package edu.washington.cs.workflow.analysis.guistructure;

import edu.washington.cs.workflow.util.Utils;

public class UIActionEntity implements EventEntity {
	
	public static String TYPE = EventEntity.TYPE.UIActionEntity.toString() + ": ";
	
	public final String actionDesc;
	public final long timestamp;
//	public final long thizObjHash;
	
	public UIActionEntity(String actionDesc) {
		this(actionDesc, System.currentTimeMillis());
//		this.thizObjHash = System.identityHashCode(obj);
	}
	
	UIActionEntity(String actionDesc, long timestamp) {
		Utils.checkNotNull(actionDesc);
		this.actionDesc = actionDesc;
		this.timestamp = timestamp;
	}
	
	public String toString() {
		String action = this.actionDesc.replace('#', ' '); //remove the # symbol
		return TYPE + EventEntity.SEP + action + EventEntity.SEP + this.timestamp;
	}
	
	public static UIActionEntity recover(String line) {
		String[] items = line.split(EventEntity.SEP);
		Utils.checkTrue(items.length == 3, line);
		Utils.checkTrue(items[0].equals(TYPE));
		long timestamp = Long.parseLong(items[2]);
		return new UIActionEntity(items[1], timestamp);
	}
	
	public int hashCode() {
		return this.actionDesc.hashCode();
	}
	
	public boolean equals(Object o) {
		if(!(o instanceof UIActionEntity)) {
			return false;
		}
		return this.actionDesc.equals(((UIActionEntity)o).actionDesc);
	}
}
